
import './App.css';
import React, { useEffect } from 'react';
import {
  BrowserRouter,
  Route,
  Switch
} from 'react-router-dom'
// import { isLogin, removeAduidInfo, removeDeviceIDInfo, removeUserInfo } from './utils/storage';

// const Login = React.lazy(()=> import('@/pages/Login'))
// const Home = React.lazy(()=> import('@/pages/Home'))

import Login from '@/pages/Login';
import Home from '@/pages/Home';
import TabbarLayout from './pages/TabbarLayout';
import Proof from './pages/Proof';
import Me from './pages/Me';
import { Redirect } from 'react-router-dom/cjs/react-router-dom.min';
import Apply from './pages/Loan/Apply';
import Review from './pages/Loan/Review';
import Launch from './pages/Launch';
import Reject from './pages/Loan/Reject';
import Loaning from './pages/Loan/Loaning';
import Repay from './pages/Loan/Repay';
import FingerprintJS from '@fingerprintjs/fingerprintjs'
import DeviceID from './utils/deviceId';
// import { generateAudid } from './utils/aduid';
// import { useDispatch } from 'react-redux';
import ProofMobile from './pages/Proof/Mobile';
import ProofFrequentlyApps from './pages/Proof/FrequentlyApps';
import ProofFace from './pages/Proof/Face';
import LoginFB from './pages/Login/LoginFB';
// import LoginAd from './pages/LoginAd';
import AddHomeEvent from './utils/addHomeEvent';
import LoginAd from './pages/LoginAd/LoginAd';
import SmartChat from './utils/smartChat';
import PrivacyPolicy from './pages/PrivacyPolicy/PrivacyPolicy';
import Guide from './pages/Loan/Guide/Guide';
import WalletList from './pages/Proof/Wallet/WalletList';
import WalletMoreBind from './pages/Proof/Wallet/WalletMoreBind';
import WalletWaveBind from './pages/Proof/Wallet/WalletWaveBind';
import ProofIdCard from './pages/Proof/IDCard/idcard';

function App() {

  //移除登录信息
  // removeUserInfo()

  //上报aduid

  //获取 Redux 分发器
  // const dispatch = useDispatch()


  //初始化指纹
  useEffect(() => {

    //移除登录信息
    // removeUserInfo()
    // removeAduidInfo()
    // removeDeviceIDInfo()

    //初始化 aduid
    // const gAduid = DeviceID.getAduid()
    // console.log("启动初始化 gaudid: " + gAduid)

    //初始化 smart chat
    SmartChat.init();

    //初始化 设备id
    if (!DeviceID.isValidVistorId()) {
      //初始化
      const fpPromise = FingerprintJS.load()

      //获取设备id
      fpPromise
        .then(fp => fp.get())
        .then(result => {
          DeviceID.saveVisitorId(result.visitorId)
          console.log("启动初始化 fingerprint: " + result.visitorId)

          //保存aduid
          //doSaveAduid()
        })
    } else {
      //保存aduid
      //doSaveAduid()
    }

    //监听安装事件
    AddHomeEvent.addBeforeInstallPromptEventListener()

    //注册service worker
    // if ('serviceWorker' in navigator) {
    //   navigator.serviceWorker.register('/service-worker.js')
    //     .then(function (registration) {
    //       console.log('Service Worker registered with scope:', registration.scope);
    //     })
    //     .catch(function (error) {
    //       console.error('Service Worker registration failed:', error);
    //     });
    // }

  }, [])

  return (
    <BrowserRouter basename="/h5loancentfcfa">
      <div className="AppRoot">
        <div className="App">

          <Switch>
            <Route path="/tabbarlayout"><TabbarLayout /></Route>
            <Route path="/proof"><Proof /></Route>
            <Route path="/proofmobile"><ProofMobile /></Route>
            <Route path="/prooffrequentlyapps"><ProofFrequentlyApps /></Route>
            <Route path="/proofface"><ProofFace /></Route>
            <Route path="/proofocr"><ProofIdCard /></Route>
            <Route path="/login"><Login /></Route>
            <Route path="/loginfb"><LoginFB /></Route>
            <Route path='/loginad' ><LoginAd /></Route>
            <Route path='/home' ><Home /></Route>
            <Route path='/me' ><Me /></Route>
            <Route path='/apply' ><Apply /></Route>
            <Route path='/review' ><Review /></Route>
            <Route path='/reject' ><Reject /></Route>
            <Route path='/loaning' ><Loaning /></Route>
            <Route path='/repay' ><Repay /></Route>
            <Route path='/launch' ><Launch /></Route>
            <Route path='/privacy' ><PrivacyPolicy /></Route>
            <Route path='/guide' ><Guide /></Route>

            <Route path='/proofwalletlist' ><WalletList /></Route>
            <Route path='/proofwalletmorebind' ><WalletMoreBind /></Route>
            <Route path='/proofwalletwavebind' ><WalletWaveBind /></Route>

            {/* 直接去启动页 */}
            <Redirect to='/launch'></Redirect>

          </Switch>
        </div>
      </div>
    </BrowserRouter>
  );
}

export default App;
